Ext.define('App.iteration.view.IterationList', {
    extend: 'Extend.grid.CrudGridPanel',
    alias: 'widget.IterationList',
    requires: ['App.iteration.viewmodel.IterationViewModel'],
    viewModel: 'IterationViewModel',
    config: {
        tbar: {
            quickCreate: {
                hidden: true
            },
            batchCreate: {
                text: '批量创建',
                handler: function () {
                    var targetGrid = this.up('CrudGridPanel');
                    Ext.create('App.iteration.view.BatchCreate', {
                        targetGrid: targetGrid
                    }).show().loadRecord(Ext.create('Ext.data.Model', {project: {id: app.project.id}}));
                }
            }
        }
    },
    bind: {
        store: '{Query}',
        columns: '{columns}',
        search: '{search}'
    },
    editor: {
        formClazz: 'App.iteration.view.IterationEditor',
        save: 'iteration/save_iteration',
        get: 'iteration/get_by_id',
        del: 'iteration/deletes',
        model: 'App.iteration.model.IterationModel'
    },
    addHandler: function () {
        this.editHandler(null, false, {project: {id: app.project.id}})
    },
    deleteHandler: function (ids, messages) {
        var me = this;
        Extend.Msg.confirm('确认', '请确定您是否要删除选择的迭代数据，删除迭代数据时同时将删除以下数据？', ['相关联数据源', '相关联迭代报表'],
            function (opt) {
                if (opt === 'yes') {
                    me.doDelete(ids);
                }
            }
        )
    }
});
Ext.define('App.iteration.view.BatchCreate', {
    extend: 'Extend.window.FormWindow',
    url: 'iteration/save_iteration_batch',
    config: {
        closeBySave: true,
        window: {
            title: '批量创建',
            width: 550,
            height: 350
        },
        entity: 'entity'
    },
    defaults: {
        columnWidth: 1,
        allowBlank: false,
        beforeLabelTextTpl: ['<span style="color:red;">*</span>'],
        blankText: '不允许为空'
    },
    items: [{
        xtype: 'hidden',
        fieldLabel: 'ID',
        name: 'id',
        allowBlank: true
    }, {
        xtype: 'datefield',
        fieldLabel: '开始时间',
        name: 'planedStartDate',
        format: 'Y-m-d',
        editable: false
    }, {
        xtype: 'numberfield',
        fieldLabel: '周期天数',
        name: 'interval',
        decimalPrecision: 0,
        minValue: 1
    }, {
        xtype: 'numberfield',
        fieldLabel: '起始编号',
        name: 'number',
        decimalPrecision: 0
    }, {
        xtype: 'numberfield',
        fieldLabel: '迭代次数',
        name: 'iterationNumber',
        decimalPrecision: 0,
        minValue: 1
    }, {
        xtype: 'hidden',
        name: 'project.id'
    }]
});